package com.cjq.springmvc.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cjq.springmvc.annotation.CjqController;
import com.cjq.springmvc.annotation.CjqQualifier;
import com.cjq.springmvc.annotation.CjqRequestMapping;
import com.cjq.springmvc.annotation.CjqRequestParam;
import com.cjq.springmvc.service.IUserService;

@CjqController
@CjqRequestMapping(value = "/user")
public class UserController {

	@CjqQualifier(value = "userServiceImpl")
	private IUserService userService;

	@CjqRequestMapping("/query")
	public void query(HttpServletRequest request, HttpServletResponse response, @CjqRequestParam("name") String name) {
		try {
			PrintWriter pw = response.getWriter();
			String result = userService.query(name);
			pw.write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@CjqRequestMapping("/insert")
	public void insert(HttpServletRequest request, HttpServletResponse response) {
		try {
			PrintWriter pw = response.getWriter();
			String result = userService.insert("0000");
			pw.write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@CjqRequestMapping("/update")
	public void update(HttpServletRequest request, HttpServletResponse response, String param) {
		try {
			PrintWriter pw = response.getWriter();
			String result = userService.update(param);
			pw.write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
